<%@ page contentType="text/html; charset=utf-8" language="java"  errorPage="" %>
<%@ page import="com.netscenery.yang.model.Leaf" %>
<%@ page import="com.netscenery.yang.model.Env" %>
<%@ page import="operate.OperateType"%>
<%@page import="offer.GetDataSource"%>
<%@page import="com.netscenery.yang.model.BuiltinType"%>
<%@page import="java.util.ArrayList"%>
<%@page import="offer.SessionObj"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
Leaf leaf = new Leaf(new Env(),"MyLeaf");
//获取结点对象
Object itemNode = request.getAttribute("itemNode");
Object opType   = request.getAttribute("opType"); //获取操作对象
if( null != itemNode){
	leaf = (Leaf)itemNode;
}
SessionObj sessionObj = (SessionObj)request.getSession().getAttribute("sessionObj");
String control_disabled = "";
if(!sessionObj.getModuleStatus().toString().equalsIgnoreCase("EDITING")){
 	control_disabled ="disabled='disabled'";
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Leaf</title>
    <meta http-equiv="Pragma" content="no-cache" />
    <meta http-equiv="Cache-Control" content="no-cache" />
    <meta http-equiv="Expires" content="0" />
	<link rel="stylesheet" type="text/css" href="<%=basePath%>/css/items.css" />
	<link rel="stylesheet" type="text/css" href="<%=basePath%>/css/subItems.css" />
	<link rel="stylesheet" type="text/css" href="<%=basePath%>/css/Tab.css" />
    <script type="text/javascript"  src="<%=basePath%>jstree-v.pre1.0/_lib/jquery.js"></script>
    <script type="text/javascript"  src="<%=basePath%>js/StringUtil.js"></script>
    <script type="text/javascript"  src="<%=basePath%>js/IfFeature.js"></script>
    <script type="text/javascript"  src="<%=basePath%>js/Leaf.js"></script>
    <script type="text/javascript"  src="<%=basePath%>js/Tab.js"></script>
</head>

<body class="body">
<script type="text/javascript">
 function bodyLoad(){
 	<% if( (null != itemNode) 
        &&  (!opType.toString().equalsIgnoreCase(OperateType.LOAD))){ %>
    <%   		 if(opType.toString().equalsIgnoreCase(OperateType.ADD)
	           || opType.toString().toString().equalsIgnoreCase(OperateType.MODIFY_INCLUDE_NAME)){ %>
	   		 	 //新增节点时，重新加载数
	   		 	 parent.reloadTreeWithNode(document.getElementById("nodeId").value);
    <%   		 } %>
			 $("#opNoticeSpan").html("操作成功！");
   		 	 setTimeout(function(){$("#opNoticeSpan").html("")},3000);
   <% }%>
   		if($("#_derivedType").html().trim().length != 0){
	 		$("#DerivedType_DIV").css("display", "block");
			$("#DerivedType_DIV").addClass("itemDiv");
			$("#FrashDerivedButton").css("display", "");
 		} 
 }
 
 $(document).ready(function(){
     $("#submitButton").click(function(){
	     $(":input").css("border-color","");
     	 if($("#_name").val().trim().length == 0){
         $("#_name").css("border-color","red");
         alert("name 不能为空！");
         return;
     }
     //名字验证
     if(!nameVerify($("#_name").val().trim(),$("#_name"))){
     	return;
     }
     if($("#_baseType").val().trim().length == 0){
        $("#_baseType").css("border-color","red");
        alert("Type 不能为空！");
        return;
     }
    document.getElementById("LeafForm").submit(); 
	});
	bodyLoad();
	tabLaod();
	load_Feature();
 });
 //用于保存节点中的If Feature name的列表 与IfFeature.js配合使用
 var availableFeatures = "<%= GetDataSource.GetAvailableIfFeatureList(leaf)%>";
 var currNodeFeatures  = "<%= GetDataSource.GetCurrNodeIfFeatureList(leaf)%>";
 	
 function Show_TypeEdit(){
 	var baseType    = document.getElementById("_baseType").value;
 	var derivedType = document.getElementById("_derivedType").value;
 	if("" == baseType){
 	    alert("Type:不能为空！");
 	    return false;
 	}
 	openTab("type");
 	var url = "<%=basePath%>GoToFindNodeTypeServlet?parent_nodeId="+document.getElementById("nodeId").value+"&baseType="+baseType+"&derivedType="+derivedType;
 	opensrc("Type_Iframe",url);
 } 	
</script>
 <!-- ***************************************** Tab Navigate Begin **************************************  -->
 <div class="navTitle" style="display:none;">
   <ul id="navTabTitle">
     <li id="mainContent_ico" onclick="showThis('mainContent')">Leaf Main Content</li>
     <li id="mimInfo_ico"><span onclick="showThis('mimInfo')">MimInfo Edit</span><img onclick="closeTab('mimInfo')" class='TitleLiImg' width='10' height='16' src='<%=basePath %>/images/delete.png' /></li>
     <li id="type_ico"><span onclick="showThis('type')">Type Edit</span><img onclick="closeTab('type')" class='TitleLiImg' width='10' height='16' src='<%=basePath %>/images/delete.png' /></li>
   </ul>
   <div style="clear:both;"></div>
 </div>
 <div id="type_tab" style="display:none;padding:0px;margin:0px;max-height:560px;height:560px;">
 <iframe width="100%" id="Type_Iframe" name="Type_Iframe"  height=100% border="0" frameborder="0" src=""  ></iframe>
 </div>
 <!--  
 <div id="mimInfo_tab"  style="display:none;padding:0px;margin:0px;max-height:560px;height:560px;">
 <iframe width="100%" id="MimInfo_Iframe" name="MimInfo_Iframe"  height=100% border="0" frameborder="0" src=""  ></iframe>
 </div>
 -->
 <!-- ***************************************** Tab Navigate End   **************************************  -->
 <div id="mainContent_tab" class="" style="padding:0px;margin:0px;">
 <!-- ****************************************************************************************************** -->
 <form id="LeafForm" method="post" action="<%=basePath %>LeafOpreateServlet" class="IndexFormStyle" >
   <input type="hidden"  id="nodeId" name="nodeId" value="<%=request.getAttribute("nodeId") %>"  />
   <div id="TableContent" class="tableContent" >
	   <div class="itemTitle">
	           The Leaf [<%=leaf.getName() %>] information  
	   </div>
	   <div class="itemDiv">
	     <span class="textSpan">&nbsp;Leaf name:</span>
	     <input class="inputText" id="_name" name="_name" value="<%=leaf.getName()==null?"":leaf.getName()%>"  />
	   </div>
	   <div class="itemDiv">
	      <% if(!leaf.isConfig()){ %>
	          &nbsp;<input type="checkbox" id="isConfig" name = "isConfig"  value="true" />Config
	         <%} else{%> 
	          &nbsp;<input type="checkbox" id="isConfig" name = "isConfig" checked="checked" value="true" />Config
	         <%}%> 
	   </div>
	   <div class="itemDiv">
	     <span class="textSpan">&nbsp;Default:</span>
	     <input class="inputText" id="_default" name="_default" value="<%=leaf.getDefaultValue()==null?"":leaf.getDefaultValue()%>"  />
	   </div>
	   <div class="itemDiv">
	     <% if(!leaf.isMandatory()){ %>
	          &nbsp;<input type="checkbox" id="isMandatory" name = "isMandatory"  value="true" />Mandatory
	         <%} else{%> 
	          &nbsp;<input type="checkbox" id="isMandatory" name = "isMandatory" checked="checked" value="true" />Mandatory
	         <%}%> 
	   </div>
	   <!--  
	   <div class="itemDiv">
		   <span class="textSpan">&nbsp;MimInfo:</span>
		   <input class="inputText" id="_mimInfoName" name="_mimInfoName" value="" /> 
          <input type="button" id="_mimInfoEdit" value = "Edit MimInfo"  onclick="Show_MimIfoEdit()" />
	     <span class="notNullSpan">*</span>
	   </div>
	   -->
	   <div class="itemDiv">
	     <span class="textSpan">&nbsp;Type:</span>
	     <select style="width:305px;   height:23px;" onchange="getDerivedType(this.value)"   class="inputSelect" id="_baseType" name="_baseType">
	          <% ArrayList<String> baseTypeList = BuiltinType.getBuiltinTypes(); %>
	          <% if(null ==leaf.getType() || null ==leaf.getType().getBase()){ %>
	          	   <option  value="" ></option>  
	          <% } %>
	          <% for(int i = 0 ; i < baseTypeList.size(); i++ ){ %>
	          <%     if(null !=leaf.getType()&& null !=leaf.getType().getBase()&& baseTypeList.get(i).equalsIgnoreCase(leaf.getType().getBase().getFieldName())){ %>  
	                    <option  value="<%= baseTypeList.get(i)%>" selected="selected"><%=baseTypeList.get(i) %></option>
	          <%     }else{ %> 
	                    <option  value="<%= baseTypeList.get(i)%>" ><%=baseTypeList.get(i) %></option>   
	          <%     }
	             } %>
	     </select>
	     <input type="button" id="_typeEdit" value="Edit Type" onclick="Show_TypeEdit()" style="display:" />
	     <span class="notNullSpan">*</span>
	     <input type="hidden" id="_typehideValue" value="" />
	   </div>
	   <div id="DerivedType_DIV" style="display:none;" >
	     <span class="textSpan">&nbsp;DerivedType:</span>
	     <select style="width:305px;   height:23px;"   class="inputSelect" id="_derivedType" name="_derivedType">
	      <% if(null !=leaf.getType()&& leaf.getType().isDerivedType()){ %>
             <option  value="<%= leaf.getType().getDerived().getName() %>" selected="selected"><%=leaf.getType().getDerived().getName() %></option>
	     <% } %>
	     </select>&nbsp;<input type="button" id="FrashDerivedButton" style="display:none;" value = " Modify " onclick ="FrashDerivedType()" />
	    
	   </div>
	   <div class="itemDiv">
	     <span class="textSpan">&nbsp;Status:</span>
	     <select style="width:305px;   height:23px;"   class="inputSelect" id="_status" name="_status">
	          <% for(int i = 0 ; i < GetDataSource.getStatusList().length ; i++ ){ %>
	          <%     if(leaf.getStatus().getStatus().equalsIgnoreCase(GetDataSource.getStatusList()[i])){ %>  
	                    <option  value="<%= GetDataSource.getStatusList()[i]%>" selected="selected"><%=GetDataSource.getStatusList()[i] %></option>
	          <%     }else{ %> 
	                    <option  value="<%= GetDataSource.getStatusList()[i]%>" ><%=GetDataSource.getStatusList()[i] %></option>   
	          <%     }
	             } %>
	     </select>
	   </div>
	    <div class="itemDiv">
	     <span class="textSpan">&nbsp;Units:</span>
	     <input class="inputText" id="_units" name="_units" value="<%=leaf.getUnits()==null?"":leaf.getUnits()%>"  />
	   </div>
	   <!-- ***********************If Feature HTML part     Begin *************************************** -->
	   <input type="hidden" id="featureParam" name="featureParam" value="" />
	   <div id="If_Feature_Content" class="itemDiv">
	       
	   </div>
	   <!-- ***********************If Feature HTML part     End ***************************************** -->
	   <div class="itemDiv">
	   		<span class="textSpan">&nbsp;Description:</span><br/>
	    	<textarea class="textArea"  id="description" name="description"><%=leaf.getDescription()==null?"":leaf.getDescription() %></textarea>
	   </div>

	   <div class="itemDiv">
	   		<span class="textSpan">&nbsp;Reference:</span><br/>
	    	<textarea class="textArea"  id="reference" name="reference"><%=leaf.getReference()==null?"":leaf.getReference() %></textarea>
	   </div>
   </div>
   <div id="submitContent" class="submitContent">
     <span id="opNoticeSpan" style="color:red;" ></span>
     <span class="textSpan">&nbsp;</span>
     <input type="button" id="submitButton"  value="Apply"  />
   </div>
   </form>
 <!-- ****************************************************************************************************** -->
 </div>
</body>
</html>